home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_056 / mcad / tdp / source / tdp.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  135 lines

  1. /***************************************************************************
  2. *                    Copyright (c) 1986, Tim Mooney                        *
  3. *                                                                          *
  4. *      This software is released into the public domain.  You may freely   *
  5. *   use, copy, modify, and redistribute it if this notice is retained.     *
  6. *   You may not sell it, but you may charge a nominal copying/hassle fee   *
  7. *   for making it available.                                               *
  8. *                                                                          *
  9. ***************************************************************************/
  10.  
  11. #define MAIN_MODULE 1
  12. #include "tdp.h"
  13.  
  14. #define NAMELEN 30
  15. char *strncpy(), line[80], *cb;
  16. void trch();
  17. int numeric();
  18. FILE *fp, *fopen();
  19.  
  20. /*************/
  21. main(argc,argv)
  22. char *argv[];
  23. int argc;
  24. {
  25.    register short i=0;
  26.    int keepgoing;
  27.    char filename[NAMELEN];
  28.  
  29.    /*** PROCESS COMMAND LINE ***/
  30.    if ((argc < 2) || (argv[1][0] == '?')) {
  31.       printf("usage:  tdp [-d#] [-n] [-a] [-i] [-b] filename\n");
  32.       printf("    # is debug level, 0 => no debug\n");
  33.       printf("   -n disables plotting of crossnet\n");
  34.       printf("   -a enables plotting of axes\n");
  35.       printf("   -i plots white on black\n");
  36.       printf("   -b plots bottom side also\n");
  37.       exit(0);
  38.    }
  39.      
  40.    while (++i < argc) {
  41.       if (argv[i][0] == '-') {
  42.            if (argv[i][1] == 'd') debug = atoi(&argv[i][2]);
  43.          else if (argv[i][1] == 'n') netplot = 'N';
  44.          else if (argv[i][1] == 'a') axes = 'Y';
  45.          else if (argv[i][1] == 'i') inverse_vid = TRUE;
  46.          else if (argv[i][1] == 'b') nsides = 2;
  47.       }
  48.       else
  49.          (void) strncpy(filename,argv[i],NAMELEN);
  50.    }
  51.    
  52.    FFPLARGE = 1.0e10; FFPSMALL = 1.0e-10;
  53.    d2r = (FFP)DEG2RAD;
  54.  
  55.    /*** LOOP UNTIL USER SAYS TO QUIT ***/
  56.    for (ans = 'y' ; ans != 'n';) {
  57.       printf("phi, theta: \x9b2m(suggest 40 -70)\x9bm > ");
  58.       while (!(cb = gets(line)));
  59.       if (*cb) {
  60.          if (numeric(cb)) phi = atoFFP(getwrd(&cb));
  61.          while ((int)(phi) > 180) phi -= 360;
  62.          while ((int)(phi) < -180) phi += 360;
  63.          if (numeric(cb)) theta = atoFFP(getwrd(&cb));
  64.          while ((int)(theta) > 180) theta -= 360.;
  65.          while ((int)(theta) < -180) theta += 360;
  66.          if (debug) printf("phi=%f, theta=%f\n", phi, theta);
  67.          phi *= d2r; theta *= d2r;
  68.       }
  69.  
  70.       if ((netplot != 'Y') && (netplot != 'N')) {
  71.          printf("Want net plot? <y | Y | n | N> (cap: don't ask again) > ");
  72.          while (!gets(str));
  73.          if ((*str=='y')||(*str=='Y')||(*str=='n')||(*str=='N')) netplot=*str;
  74.       }
  75.       if ((axes != 'Y') && (axes != 'N')) {
  76.          printf("Want axes? <y | Y | n | N> (cap: don't ask again) > ");
  77.          while (!gets(str));
  78.          if ((*str=='y')||(*str=='Y')||(*str=='n')||(*str=='N')) axes=*str;
  79.       }
  80.       
  81.       /* GET DATA */
  82.       fp = fopen(filename,"r");
  83.       if (fp != NULL) {
  84.          (void)fread((char *)&nxpts,sizeof(int),1,fp);
  85.          (void)fread((char *)&nypts,sizeof(int),1,fp);
  86.          (void)fread((char *)zd,sizeof(float),nxpts*nypts,fp);
  87.          if (debug) printf("%d floats read.  ",nxpts*nypts);
  88.          (void) fclose(fp);
  89.       }
  90.       else {
  91.          printf("can't open %s\n",filename);
  92.          exit(1);
  93.       }
  94.       
  95.  
  96.       /* PLOT DATA */
  97.       printf("\x9b2mWorking...\x9bm ");
  98.       plot3d();
  99.  
  100.       /* CHECK USER */
  101.       keepgoing = TRUE; PlotFile = FALSE;
  102.       do {
  103.          Wait(1 << w->UserPort->mp_SigBit);
  104.          while (message = (struct IntuiMessage *) GetMsg(w->UserPort)) {;
  105.             class = message->Class;
  106.             code = message->Code;
  107.             ReplyMsg(message);
  108.             if ((class == MENUPICK) && (code != MENUNULL)) {
  109.                switch (MENUNUM(code)) {
  110.                case M_PROJECT:
  111.                   switch (ITEMNUM(code)) {
  112.                   case MI_OPEN: break;
  113.                   case MI_PLOT:
  114.                      pfp = fopen("tdp.plt","w"); PlotFile = TRUE; break;
  115.                   case MI_TOMCAD:
  116.                      mfp = fopen("tdp.cad","w"); To_mCAD = TRUE; break;
  117.                   case MI_QUIT: keepgoing = FALSE; break;
  118.                   default: break;
  119.                   }
  120.                   break;
  121.                default: break;
  122.                }
  123.             }
  124.          }
  125.       } while(keepgoing);
  126.  
  127.       CleanUp();      
  128.  
  129.       printf("continue?  < y | n > ");
  130.       while (!gets(str)); ans=*str;
  131.       if (ans == 'N') ans = 'n';
  132.    }
  133.    return(0);
  134. }
  135.